import { create } from 'zustand'
import { immer } from 'zustand/middleware/immer'
// import { logger } from './logger'
import { devtools } from 'zustand/middleware'
// devtools 是 zustand 提供的一个用于调试的工具，它可以帮助我们更好地管理状态。
// 需要安装浏览器插件 Redux DevTools 下载地址
// 在浏览器中打开 Redux DevTools 插件，并连接到当前页面
interface StateData {
    count: number,
    increment: () => void,
    decrement: () => void
    testObj: {
        name: string,
        age: number
    },
    updateName: (name: string) => void
    updateAge: (age: number) => void
}

// 
export const useDevToolsStore = create<StateData>()(immer(devtools((set) => ({
    count: 0,
    increment: () => set((state) => {
        state.count++
    }),
    decrement: () => set((state) => {
        state.count--
    }),
    testObj: {
        name: '测试二级对象',
        age: 18
    },
    updateName: (name: string) => set((state) => {
        state.testObj.name = name
    }),
    updateAge: (age: number) => set((state) => {
        state.testObj.age = age
    })
}),
    {
        name: 'zustandMiddleware', // store 的名称
        enabled: true // 是否开启
    }

)))